package com.wnxy.pawnbackgroundsystem.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wnxy.pawnbackgroundsystem.dto.GetAllWareHousePageDto;
import com.wnxy.pawnbackgroundsystem.dto.SelectHouseDto;
import com.wnxy.pawnbackgroundsystem.dto.StoreDto;
import com.wnxy.pawnbackgroundsystem.dto.WareHouseDto;
import com.wnxy.pawnbackgroundsystem.param.GetHouseParam;
import com.wnxy.pawnbackgroundsystem.param.GetStoreParam;
import com.wnxy.pawnbackgroundsystem.param.UpdateHouseParam;
import com.wnxy.pawnbackgroundsystem.param.WarehouseParam;
import com.wnxy.pawnbackgroundsystem.response.Result;
import com.wnxy.pawnbackgroundsystem.service.IStoreWarehouseService;
import com.wnxy.pawnbackgroundsystem.service.IWarehouseService;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.SplitReturn;
import net.sf.jsqlparser.statement.truncate.Truncate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 仓库管理表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-10-14
 */
@RestController
@RequestMapping("/pawnbackgroundsystem/warehouse")
@CrossOrigin("*")
public class WarehouseController {
    @Autowired
    private IWarehouseService iWarehouseService;

    @ApiOperation("删除仓库")
    @GetMapping("/delWarehouse")
    public Result delWarehouse(Integer houseId){
        iWarehouseService.delWarehouse(houseId);
        return new Result(true,"2002","删除成功",null);
    }


    @ApiOperation("新增仓库")
    @PostMapping("/insertHouse")
    public Result insertHouse(@RequestBody WarehouseParam warehouseParam){
        System.out.println(warehouseParam);
        iWarehouseService.insertHouse(warehouseParam);
        return new Result(true,"2002","删除成功",null);
    }

    @ApiOperation("查询所有仓库")
    @GetMapping("/getAllHouse")
    public Result<List<WareHouseDto>> getAllHouse(){
        List<WareHouseDto> whd=iWarehouseService.getAllHouse();
        return new Result(true,"2002","查询成功",whd);
    }

    @ApiOperation("分页模糊查询")
    @PostMapping("/selectHouse")
    public Result selectHouse(@RequestBody GetHouseParam getHouseParam){

        IPage<SelectHouseDto> selectHouseDtoIPage = iWarehouseService.houseDto(getHouseParam);

        return  new Result(true,"2002","查询成功",selectHouseDtoIPage);
    }

    @ApiOperation("修改仓库信息")
    @PostMapping("/updateHouse")
    public Result updateHouse(@RequestBody UpdateHouseParam up){
        System.out.println(up);
        iWarehouseService.updateHouse(up);
        return  new Result(true,"2002","修改成功",null);
    }
    @ApiOperation("/新增仓库获取已有门店信息")
    @PostMapping("/getAllWareHouse")
    public Result getAllWareHouse(@RequestBody GetHouseParam getHouseParam){
        System.out.println("----------");
        System.out.println(getHouseParam);
        GetAllWareHousePageDto allWareHouse = iWarehouseService.getAllWareHouse(getHouseParam);
        return new Result(true,"2002","查询集合成功",allWareHouse);

    }
    @ApiOperation("/修改仓库获取对应关联门店")
    @GetMapping("/getStoreName")
    public Result getStoreName(Integer warehouseId){

        List<String> storeName=iWarehouseService.getStoreName(warehouseId);

        return new Result(true,"2002","查询集合成功",storeName);
    }



}

